<?php
/**
* processlogin.php
* v0.01
* 1/28/2011
* This source code checks if the log-in credentials are stored in the database.
* It redirects to the analyst page if the user is an analyst.
* It redirects to the administrator page if the user is an administrator.
* If others, it returns to the log-in page, generating an error.
*/
require("libraries/LoginLib.php");

$username = $_POST["username"];				//The submitted username
$password = $_POST["password"];				//The submitted password

/*Detect if the login attempt is an actual account*/
$valid = LookFor($username, $password, "CASL", "localhost", "login", "login"); 
if ($valid == "ADMINISTRATOR" || $valid == "ANALYST"){
	session_start();
	$_SESSION["username"] = $username;
	$loginname = GetUsername($username,'casl','localhost','login','login');
	$_SESSION["name"] = $loginname;
	
	if ($valid == "ADMINISTRATOR"){
		/*Redirect to administrator page*/
		$_SESSION["usertype"] = "Administrator";
		$_SESSION["administrator"] = $username;
		header("Location: AdministratorHomepage.php");
	}
	else if ($valid == "ANALYST"){
		/*Redirect to analyst page*/
		$_SESSION["usertype"] = "Analyst";
		$_SESSION["analyst"] = $username;
		header("Location: AnalystHomepage.php");
	}
}
else{
	/*Redirect to login page*/
	header("Location: index.php?error=false");
}
?>